
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "reflecxx.h"

struct config_data_t {
    char *cd_name;
    int cd_timeout;
} config_data;

extern struct reflecxx_full_type config_data_t_type_info;

int main(int argc, char *argv[])
{
    struct reflecxx_buffer rb = REFLECXX_EMPTY_BUFFER;
    int retval = EXIT_SUCCESS;
    struct reflecxx_error re;
    reflecxx_primitive_t rp;
    char line[1024];

    while (fgets(line, sizeof(line), stdin) != NULL) {
	if (!rbappendf(&rb, strlen(line), "%s", line)) {
	    perror("error reading config file\n");
	    return EXIT_FAILURE;
	}
    }

    rp.rp_pointer = &config_data;
    if (rb.rb_used == 0) {
	fprintf(stderr, "error: no config file given\n");
    }
    else if (!reflecxx_scan(&rb, &config_data_t_type_info, &rp, &re)) {
	fprintf(stderr,
		"error:%d:%d: %s\n",
		re.re_line, re.re_column,
		re.re_msg);
    }
    else {
	printf("name = %s\n", config_data.cd_name);
	printf("timeout = %d\n", config_data.cd_timeout);
    }

    return retval;
}
